<html>
<head><meta charset="utf-8"><title>something missing from documented struct expr grammar? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/something.20missing.20from.20documented.20struct.20expr.20grammar.3F.html">something missing from documented struct expr grammar?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240056957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/something%20missing%20from%20documented%20struct%20expr%20grammar%3F/near/240056957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/something.20missing.20from.20documented.20struct.20expr.20grammar.3F.html#240056957">(May 24 2021 at 14:16)</a>:</h4>
<p>i'm confused by what seems to be an omission from the grammar in the Reference.<br>
in the example at <a href="https://doc.rust-lang.org/reference/items/implementations.html#trait-implementations">https://doc.rust-lang.org/reference/items/implementations.html#trait-implementations</a><br>
there's a struct expression in</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">fn</span> <span class="nf">clone</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Circle</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">*</span><span class="bp">self</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>that seems to initialize <code>Circle</code> by dereferencing <code>self</code>. <code>Circle</code> is defined as</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Circle</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">radius</span>: <span class="kt">f64</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">center</span>: <span class="nc">Point</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>the grammar doesn't show anything resembling the single-expression syntax like that used in the <code>clone()</code> above that i could find. am i missing something?<br>
<a href="https://doc.rust-lang.org/reference/expressions/struct-expr.html">https://doc.rust-lang.org/reference/expressions/struct-expr.html</a><br>
there's <em>StructBase</em> that contains an expression, but it can't appear without <code>..</code></p>



<a name="240057203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/something%20missing%20from%20documented%20struct%20expr%20grammar%3F/near/240057203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/something.20missing.20from.20documented.20struct.20expr.20grammar.3F.html#240057203">(May 24 2021 at 14:17)</a>:</h4>
<p>That is not a struct expression, it's a block with a trailing expression of <code>*self</code></p>



<a name="240057729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/something%20missing%20from%20documented%20struct%20expr%20grammar%3F/near/240057729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/something.20missing.20from.20documented.20struct.20expr.20grammar.3F.html#240057729">(May 24 2021 at 14:21)</a>:</h4>
<p>oh <span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span>  you're right. it happened to look like one, especially inline like that</p>



<a name="240127338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/something%20missing%20from%20documented%20struct%20expr%20grammar%3F/near/240127338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/something.20missing.20from.20documented.20struct.20expr.20grammar.3F.html#240127338">(May 24 2021 at 23:45)</a>:</h4>
<p>We've actually had requests for some shorthand syntax to avoid things like <code>fn new() -&gt; Self { Self { ... } }</code>. I think this thread makes a compelling argument for why we <em>shouldn't</em> have a shorthand syntax for that. :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>